﻿using System;
using System.Collections.Generic;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.para.styleenums;
using SharpSqlAnalyzer.pp.utils;

namespace SharpSqlAnalyzer.pp.processor.type.comm
{
	// Token: 0x02000249 RID: 585
	public abstract class AbstractKeyWordAlignProcessor : AbstractProcessor
	{
		// Token: 0x06001309 RID: 4873
		protected internal abstract IList<TSourceToken[]> getTSourceToken<E>(E node);

		// Token: 0x0600130A RID: 4874 RVA: 0x0031C600 File Offset: 0x0031A800
		public override void beforeProcess(TParseTreeNode node)
		{
			IList<TSourceToken[]> tsourceToken = this.getTSourceToken<TParseTreeNode>(node);
			int num = 0;
			foreach (TSourceToken[] tokenStartAndEnd in tsourceToken)
			{
				if (this.textSize(tokenStartAndEnd) > num)
				{
					num = this.textSize(tokenStartAndEnd);
				}
			}
			foreach (TSourceToken[] tokenStartAndEnd2 in tsourceToken)
			{
				this.alignText(tokenStartAndEnd2, num);
			}
		}

		// Token: 0x0600130B RID: 4875 RVA: 0x0031C698 File Offset: 0x0031A898
		private int textSize(TSourceToken[] tokenStartAndEnd)
		{
			if (tokenStartAndEnd.Length == 1)
			{
				return this.textSize(tokenStartAndEnd[0]);
			}
			TSourceToken tsourceToken = tokenStartAndEnd[0];
			TSourceToken tsourceToken2 = tokenStartAndEnd[1];
			int num = 0;
			for (int i = tsourceToken.posinlist; i <= tsourceToken2.posinlist; i++)
			{
				TSourceToken tsourceToken3 = tsourceToken.container.get(i);
				if (tsourceToken3.astext != null)
				{
					num += tsourceToken3.astext.Length;
				}
			}
			return num;
		}

		// Token: 0x0600130C RID: 4876 RVA: 0x0031C6FC File Offset: 0x0031A8FC
		private int textSize(TSourceToken token)
		{
			if (token != null && token.astext != null)
			{
				return token.astext.Length;
			}
			return 0;
		}

		// Token: 0x0600130D RID: 4877 RVA: 0x0031C716 File Offset: 0x0031A916
		private string text(TSourceToken token)
		{
			if (token != null && token.astext != null)
			{
				return token.astext;
			}
			return "";
		}

		// Token: 0x0600130E RID: 4878 RVA: 0x0031C730 File Offset: 0x0031A930
		private void alignText(TSourceToken[] tokenStartAndEnd, int maxSize)
		{
			if (tokenStartAndEnd.Length == 1)
			{
				this.alignText(tokenStartAndEnd[0], maxSize);
				return;
			}
			int num = this.textSize(tokenStartAndEnd);
			string text = Utils.createEmpty(maxSize - num);
			if (this.Option.selectKeywordsAlignOption == TAlignOption.AloLeft)
			{
				tokenStartAndEnd[1].astext = tokenStartAndEnd[1].astext + text;
				return;
			}
			TSourceToken tsourceToken = tokenStartAndEnd[0];
			string str = text;
			TSourceToken tsourceToken2 = tokenStartAndEnd[0];
			tsourceToken.astext = str + ((tsourceToken2 != null) ? tsourceToken2.ToString() : null);
		}

		// Token: 0x0600130F RID: 4879 RVA: 0x0031C7A0 File Offset: 0x0031A9A0
		private void alignText(TSourceToken token, int maxSize)
		{
			int num = this.textSize(token);
			string text = Utils.createEmpty(maxSize - num);
			if (this.Option.selectKeywordsAlignOption == TAlignOption.AloLeft)
			{
				token.astext = this.text(token) + text;
				return;
			}
			token.astext = text + this.text(token);
		}
	}
}
